package com.shqcjd.generalplatformprojectclient.widget;

import android.annotation.TargetApi;
import android.app.Dialog;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.widget.DatePicker;


import com.shqcjd.generalplatformprojectclient.R;

import java.util.Calendar;

public class DatePickerDialog extends Dialog {
    private Context context;
    private DatePicker dp_dialog_select;
    private setOnCheckDateListener listener;
    Calendar c;

    public void setOnCheckDate(setOnCheckDateListener listener){
        this.listener = listener;
    }

    public DatePickerDialog(@NonNull Context context) {
        super(context);
        this.context = context;
    }

    public DatePickerDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
    }

    protected DatePickerDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    @TargetApi(Build.VERSION_CODES.O)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_datepick_dialog);
        getWindow().setBackgroundDrawableResource(R.color.transparent);
        c = Calendar.getInstance();
        dp_dialog_select = findViewById(R.id.dp_dialog_select);
        dp_dialog_select.init(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH) , new DatePicker.OnDateChangedListener() {
            @Override
            public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                listener.onCheckDate(year, monthOfYear, dayOfMonth);
            }
        });
    }

    public interface setOnCheckDateListener{
        void onCheckDate(int year, int month, int day);
    }
}
